public class Demo5 {
    public static void main(String[] args) {
        Thread thread = new Thread(() ->{
           while (!Thread.currentThread().isInterrupted()) {

               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   //1.不操作继续执行线程
                   e.printStackTrace();
                   //2.结束线程
                   break;
                   //3.进行其它操作
               }

           }
        });
        thread.start();
        thread.interrupt();
    }
}
